<?php
/**
 * @package WordPress
 * @subpackage WP Base
**/
$theme_path = get_template_directory();
define('THEME_NAME', 'WP Base');
define('THEME_SLUG', 'wp_base');
require_once $theme_path."/includes/main.php";
$theme = new CrossThemes();
$theme->init();

if ( !class_exists( 'ReduxFramework' ) && file_exists( dirname( __FILE__ ) . '/admin/ReduxCore/framework.php' ) ) {
    require_once( dirname( __FILE__ ) . '/admin/ReduxCore/framework.php' );
}
require_once( dirname( __FILE__ ) . '/admin/options.php' );


//header
if ( ! function_exists( 'crt_title' ) ){
	function crt_title( $title, $sep ) {
		global $paged, $page;

		if ( is_feed() )
			return $title;
		
		if ( defined('WPSEO_VERSION') ) {
			return $title;
		}
		$title .= bloginfo( 'name' );

		$site_description = get_bloginfo( 'description', 'display' );
		if ( $site_description && ( is_home() || is_front_page() ) )
			$title .= " | $site_description";

		if ( $paged >= 2 || $page >= 2 )
			$title .= ' | ' . sprintf( __( 'Page %s', 'wpdance' ), max( $paged, $page ) );
		return $title;
	}
}
add_filter( 'wp_title', 'crt_title', 10, 2 );

/****************** BODY CLASS ********************/
// Add body class for wide or boxed layout
add_filter('body_class','crosstheme_layout_class_names');
function crosstheme_layout_class_names($classes) {
  global $crosstheme;
  // add 'class-name' to the $classes array
  if(isset($crosstheme['opt-layout'])) {
    $layoutstyle = $crosstheme['opt-layout'];
  } else {
    $layoutstyle = 'wide';
  }

if ($layoutstyle == "boxed") {
  $classes[] = 'crt-boxed';
}
else {
  $classes[] = 'wide';
}
  // return the $classes array
  return $classes;
}
/************************* Header First  ****************************/

if ( ! function_exists( 'crt_header_first' ) ){
	function crt_header_first() {
		?>
			<div class="header-first">
				<div  class="header-first-content container">
					<div class="header-first-left">
						<?php 
							if ( is_active_sidebar( 'crt-top-left-header-sidebar' ) ) : ?>
								<ul class="xoxo">
									<?php dynamic_sidebar( 'crt-top-left-header-sidebar' ); ?>
								</ul>
						<?php endif; ?>	
					</div>
					<div class="header-first-right">
						<div class="crt-myaccount">
							<a href="#" title="<?php _e('My Account','wpdance');?>">
								<?php if(is_user_logged_in()): ?>	
									<span><?php _e('My Account','wpdance');?></span>
								<?php else:?>
									<span><?php _e('Login / Register','wpdance');?></span>
								<?php endif;?>		
							</a>	
						</div>
						<div class="crt-mycart">
							<a href="#" title="<?php _e('View your shopping bag','wpdance');?>">
								<span><?php _e('shopping cart','wpdance');?> </span>
							</a>
						</div>
						<div class="header_search">
							<span class="search-icon"></span>
							<?php get_search_form(); ?>
						</div>
						<div class="clear"></div>
					</div>	
				</div>		
			</div>
		<?php
	}
}
add_action('crt_header','crt_header_first',10);

/************************* Header Second  ****************************/

if ( ! function_exists( 'crt_header_second' ) ){
	function crt_header_second() {
		global $crosstheme;
	?>
		<div class="header-second">
			<div class="header-second-content container">
				<div class="logo">
					<a href="<?php bloginfo('url'); ?>">
						<img src="<?php echo esc_url($crosstheme['crt_logo_upload']['url']); ?>" alt="<?php bloginfo('name'); ?>" class="normal_logo" />
					</a>
				</div>
				
				<div class="nav crt_mega_menu_wrapper">
					<?php 
						if ( has_nav_menu( 'primary' )) {
							wp_nav_menu( array( 'container_class' => 'main-menu crt-mega-menu-wrapper','theme_location' => 'primary','walker' => new CrossTheme_Walker_NavMenu_Custom() ) );
						}else{
							wp_nav_menu( array( 'container_class' => 'main-menu crt-mega-menu-wrapper', 'theme_location' => 'primary' ) ); 
						}
					?>
				</div>
			</div>
		</div>
	<?php		
	}
}
add_action('crt_header','crt_header_second',10);

/************************* Footer First  ****************************/

if ( ! function_exists( 'crt_footer_first' ) ){
	function crt_footer_first() {
		?>
		<div class="footer-first col-sm-6">
			<div class="footer-first-content">
				<?php 
					if ( is_active_sidebar( 'crt-footer-1-sidebar' ) ) : ?>
						<ul class="xoxo">
							<?php dynamic_sidebar( 'crt-footer-1-sidebar' ); ?>
						</ul>
				<?php endif; ?>	
			</div>
		</div>
		<?php		
	}
}
add_action('crt_footer','crt_footer_first',10);

/************************* Footer Seconnd  ****************************/

if ( ! function_exists( 'crt_footer_second' ) ){
	function crt_footer_second() {
		?>
		<div class="footer-second col-sm-6">
			<div class="footer-second-content">
				<?php 
					if ( is_active_sidebar( 'crt-footer-2-sidebar' ) ) : ?>
						<ul class="xoxo">
							<?php dynamic_sidebar( 'crt-footer-2-sidebar' ); ?>
						</ul>
				<?php endif; ?>	
			</div>
		</div>
		<?php		
	}
}
add_action('crt_footer','crt_footer_second',20);

/************************* Footer Third  ****************************/

if ( ! function_exists( 'crt_footer_third' ) ){
	function crt_footer_third() {
		?>
		<div class="footer-third col-sm-6">
			<div class="footer-third-content">
				<?php 
					if ( is_active_sidebar( 'crt-footer-3-sidebar' ) ) : ?>
						<ul class="xoxo">
							<?php dynamic_sidebar( 'crt-footer-3-sidebar' ); ?>
						</ul>
				<?php endif; ?>	
			</div>
		</div>
		<?php		
	}
}
add_action('crt_footer','crt_footer_third',30);

/************************* Footer Four  ****************************/

if ( ! function_exists( 'crt_footer_four' ) ){
	function crt_footer_four() {
		?>
		<div class="footer-four col-sm-6 last">
			<div class="footer-four-content">
				<?php 
					if ( is_active_sidebar( 'crt-footer-4-sidebar' ) ) : ?>
						<ul class="xoxo">
							<?php dynamic_sidebar( 'crt-footer-4-sidebar' ); ?>
						</ul>
				<?php endif; ?>	
			</div>
		</div>
		<?php		
	}
}
add_action('crt_footer','crt_footer_four',40);


/************************* Footer Bottom  ****************************/

if ( ! function_exists( 'crt_footer_bottom' ) ){
	function crt_footer_bottom() {
		global $crosstheme;
		?>
		<div class="footer-bottom">
			<div class="footer-bottom-content">
				<div id="copy-right" class="copy-right">
					<div class="copyright">
						<?php 
							if(isset($crosstheme['footer_copyright'])) { $footertext = $crosstheme['footer_copyright'];} else {$footertext = '[copyright] [the-year] [site-name] [theme-credit]';}
							$footertext = str_replace('[copyright]','&copy;',$footertext);
							$footertext = str_replace('[the-year]',date('Y'),$footertext);
							$footertext = str_replace('[site-name]',get_bloginfo('name'),$footertext);
							$footertext = str_replace('[theme-credit]','- WordPress Theme by <a href="http://www.crosstheme.com/" target="_blank">CrossThemes</a>',$footertext);
							echo do_shortcode($footertext); 
						?>
					</div>
				</div><!-- end #copyright -->
				<div class="footer-socials">
					<ul class="social-list">
						<li class="facebook first">
							<a target="_blank" href="#">
								<span class="facebook-icon"></span>
							</a>
						</li>
						<li class="twitter">
							<a target="_blank" href="#">
								<span class="twitter-icon"></span>
							</a>
						</li>
						<li class="rss">
							<a target="_blank" href="#">
								<span class="rss-icon"></span>
							</a>
						</li>
						<li class="pinterest">
							<a target="_blank" href="#">
								<span class="pinterest-icon"></span>
							</a>
						</li>
						<li class="google">
							<a target="_blank" href="#">
								<span class="pinterest-icon"></span>
							</a>
						</li>			
					</ul>
				</div>
			</div>
		</div>
		<?php
	}
}

add_action('crt_footer_bottom','crt_footer_bottom',10);





// Add more widget
if(function_exists('register_sidebar')) {
	register_sidebar(array(
		'name' => 'Top-Left Header Sidebar',
		'id' => 'crt-top-left-header-sidebar',
		'before_widget' => '<div id="%1$s" class="widget %2$s">',
		'after_widget' => '</div>',
		'before_title' => '<div class="heading"><h3>',
		'after_title' => '</h3></div>',
	));
	
	register_sidebar(array(
		'name' => 'Footer 1 Sidebar',
		'id' => 'crt-footer-1-sidebar',
		'before_widget' => '<div id="%1$s" class="widget %2$s">',
		'after_widget' => '</div>',
		'before_title' => '<div class="heading"><h3>',
		'after_title' => '</h3></div>',
	));
	
	register_sidebar(array(
		'name' => 'Footer 2 Sidebar',
		'id' => 'crt-footer-2-sidebar',
		'before_widget' => '<div id="%1$s" class="widget %2$s">',
		'after_widget' => '</div>',
		'before_title' => '<div class="heading"><h3>',
		'after_title' => '</h3></div>',
	));
	
	register_sidebar(array(
		'name' => 'Footer 3 Sidebar',
		'id' => 'crt-footer-3-sidebar',
		'before_widget' => '<div id="%1$s" class="widget %2$s">',
		'after_widget' => '</div>',
		'before_title' => '<div class="heading"><h3>',
		'after_title' => '</h3></div>',
	));
	
	register_sidebar(array(
		'name' => 'Footer 4 Sidebar',
		'id' => 'crt-footer-4-sidebar',
		'before_widget' => '<div id="%1$s" class="widget %2$s">',
		'after_widget' => '</div>',
		'before_title' => '<div class="heading"><h3>',
		'after_title' => '</h3></div>',
	));
}
